package com.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dao.mybatis.mapper.PersonMapper;
import com.entity.Pagination;
import com.entity.Person;

@Repository
public class PersonDaoImp implements PersonDao {
	@Resource
	private PersonMapper mapper;

	@Override
	public Integer insertPerson(Person person) {
		Integer i = mapper.insert(person);	
		return i;
	}

	@Override
	public List<Person> getAllPersons(Pagination pagination,Person person) {
		Map<String, Object>map = new HashMap<String, Object>();
		if(pagination!=null){
			map.put("page", pagination.getCurrentPage());
			map.put("startRow", pagination.getStartRow());
			map.put("pageSize", pagination.getEveryPage());	
		}
		if(person!=null){
			map.put("chName", person.getChName());
			map.put("sex", person.getSex());
			map.put("identityNum", person.getIdentityNum());
			
		}
		return mapper.getAllPersons(map);
	}

	@Override
	public Integer deletePerson(Person person) {
		return mapper.deleteByPrimaryKey(person.getId());
	}

	@Override
	public Integer updatePerson(Person person) {
		return mapper.updateByPrimaryKey(person);
	}

	@Override
	public int countAll(Person person) {
		return mapper.countByPerson(person);
	}

	@Override
	public Person findById(Integer id) {
		return mapper.findById(id);
	}

	@Override
	public List<Person> getAllPersonsByBirthday(Pagination pagination) {
		Map<String, Object>map = new HashMap<String, Object>();
		if(pagination!=null){
			map.put("page", pagination.getCurrentPage());
			map.put("startRow", pagination.getStartRow());
			map.put("pageSize", pagination.getEveryPage());	
		}
		return mapper.getAllPersonsByBirthday(map);
	}

	@Override
	public int countAllByBirthday() {
		return mapper.countAllByBirthday();
	}

}
